exports.add = (req,res) => {

    var bodyParams = req.routeInfo.bodyParams;

    var lastId = 0;  //新增的文档主键ID

    //新增文档信息
    function addDocs(cb){

        //新增文档
        var sql = `insert into docs values(NULL,
            '${bodyParams.d_name}',
            '${bodyParams.d_api}',
            '${bodyParams.d_method}',
            '${bodyParams.d_desc == undefined ? '' : bodyParams.d_desc}',
            '${bodyParams.d_note == undefined ? '' : bodyParams.d_note}',
            '${bodyParams.d_result}',
            '${bodyParams.d_dcid}')`;

        sqliteDb.run(sql,function(error,data){

            if(error){
                return RES.errorResponse(res,"抱歉，文档新增失败");
            }

            //获取新增的主键ID
            sql = "select last_insert_rowid() as lastId from docs limit 1";

            sqliteDb.all(sql,function(error,data){

                if(error){
                    return RES.errorResponse(res,"抱歉，文档新增失败");
                }
    
                lastId = data[0].lastId

                cb();

            });

        });

    }

    //新增文档参数
    function addDocsParams(cb){

        if(bodyParams.d_params == undefined || bodyParams.d_params.length <= 0){
            return cb();
        }

        //每个循环的处理
        function taskFun(item,index,callback){

            var sql = `insert into docs_request_parameter values(NULL,
                '${lastId}',
                '${item.drp_name}',
                '${item.drp_is_must}',
                '${item.drp_rule}',
                '${item.drp_note}',
                '${item.drp_way}')`;
            
            sqliteDb.run(sql,function(error,data){    
                callback();
            });

        }

        //创建循环
        F.SerialEach(bodyParams.d_params,taskFun,cb);
        
    }

    F.Serial([addDocs,addDocsParams],function(){
        return RES.successResponse(res,lastId);
    });


 }